﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace MSpecLauncher.Services
{
    /// <summary>
    /// Runs commands with arguments
    /// </summary>
    public class CommandRunner : ICommandRunner
    {
        /// <summary>
        /// Runs the given command with the given arguments, waiting for it to complete
        /// </summary>
        public void RunSpecs(string cmd, string args, bool visible)
        {
            System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo(cmd);
            start.Arguments = args;
            
            if (visible) start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
            else start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            //start.UseShellExecute = false;
            //start.CreateNoWindow = true;

            Process process = new Process();
            process.StartInfo = start;
            process.Start();

            // Esperamos a que acabe el proceso
            process.WaitForExit();
        }
    }

}
